<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改课程')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-goods-edit" th:object="${sysCourse}">
            <input type="hidden" id="ids" name="ids" th:value="${ids}"/>
            <input id="id" name="id" th:field="*{id}" type="hidden">
            <input id="tenantId2" name="tenantId2" th:field="*{tenantId}" type="hidden">
           <!-- <div class="form-group" th:if="${@permission.hasPermi('system:superAdmin:opt')} != 'hidden'">
                <label class="col-sm-3 control-label">请选择租户：</label>
                <div class="col-sm-8">
                    <select name="tenantId" id="tenantId"  class="form-control" disabled>
                        <option th:each="t : ${tenantList}" th:selected="${t.tenantId eq sysSubject.tenantId}"  th:text="${t.tenantName}" th:value="${t.tenantId}"></option>
                    </select>
                </div>
            </div>-->
            <h4 class="form-header h4">课程编辑</h4>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label is-required">课程名称：</label>
                        <div class="col-xs-8">
                            <input name="name" th:field="*{name}" placeholder="请填写课程名称" class="form-control" type="text" maxlength="100" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label is-required">授课方式：</label>
                        <div class="col-xs-8">
                            <select name="classType" th:field="*{classType}"  class="form-control">
                                <option value="0">线下课</option>
                                <option value="1">线上课</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">科目：</label>
                        <div class="col-sm-8">
                            <select name="subjectId" id="subjectId" required class="form-control">
                                <option value="">请选择</option>
                                <option th:each="t : ${subjectList}"  th:selected="${t.id eq sysCourse.subjectId}" th:text="${t.name}" th:value="${t.id}"></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">年级：</label>
                        <div class="col-sm-8">
                            <select name="gradeId" id="gradeId" required class="form-control">
                                <option value="">请选择</option>
                                <option th:each="t : ${gradeList}"  th:selected="${t.id eq sysCourse.gradeId}" th:text="${t.name}" th:value="${t.id}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label is-required">收费方式：</label>
                        <div class="col-xs-8">
                            <label><input type="radio" checked="" value="0" id="chargeType1" name="chargeType">&nbsp;按次收费 &nbsp;&nbsp;</label>
                            <label><input type="radio" value="1" id="chargeType2" name="chargeType">&nbsp;按期收费</label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label is-required">标准课程单价：</label>
                        <div class="col-xs-8">
                            <input name="standardCoursePrice"  th:field="*{standardCoursePrice}" placeholder="请填写标准课程单价" class="form-control" type="text" maxlength="10" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label is-required">标准课次：</label>
                        <div class="col-xs-8">
                            <input name="standardClass"  th:field="*{standardClass}" placeholder="请填写标准课次" class="form-control" type="text" maxlength="10" required>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label is-required">价格浮动上限：</label>
                        <div class="col-xs-8">
                            <input name="priceFloatUp"  th:field="*{priceFloatUp}" placeholder="请填写价格浮动上限" class="form-control" type="text" maxlength="10" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label is-required">价格浮动下限：</label>
                        <div class="col-xs-8">
                            <input name="priceFloatDown"  th:field="*{priceFloatDown}" placeholder="请填写价格浮动下限" class="form-control" type="text" maxlength="10" required>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label is-required">教学用品：</label>
                        <div class="col-xs-8">
                            <button type="button" class="btn btn-w-m btn-primary" onclick="searchGoods()" >选择</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12 table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-offset-5 col-sm-10">
                    <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
                    <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script type="text/javascript">
        jQuery.validator.addMethod("minNumber",function(value, element){
            var returnVal = true;
            inputZ=value;
            var ArrMen= inputZ.split(".");    //截取字符串
            if(ArrMen.length==2){
                if(ArrMen[1].length>2){    //判断小数点后面的字符串长度
                    returnVal = false;
                    return false;
                }
            }
            return returnVal;
        }, "小数点后最多为两位");

        var prefix = ctx + "teach/course"
        $("#form-subject-add").validate({
            onkeyup: false,
            rules:{
                name:{
                    remote: {
                        url: ctx + "teach/course/checkNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "name" : function() {
                                return $.common.trim($("#name").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                standardCoursePrice: {
                    required: true,    //要求输入不能为空
                    number: true,     //输入必须是数字
                    min: 0.01,          //输入的数字最小值为0.01，不能为0或者负数
                    minNumber: $("#standardCoursePrice").val()    //调用自定义验证
                },
                standardClass:{
                    digits:true
                },
                priceFloatUp:{
                    digits:true
                },
                priceFloatDown:{
                    digits:true
                }
            },
            messages: {
                "name": {
                    remote: "名称已存在！"
                },
                "standardCoursePrice": {
                    required: "请填写标准课次单价",
                    number: "请正确输入数值",
                    min: "输入最小数值为0.01",
                    length: "输入数字最多小数点后两位"
                }
            },
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-goods-edit').serialize());
            }
        }

        function searchGoods() {
            var url = prefix +  "/searchGoods?ids=" + $("#ids").val();
            $.modal.open("选择教学用品", url);
        }

        $(function() {
            var options = {
                url: prefix + "/toLoadGoods",
                modalName: "教学用品",
                sortName: "id",
                sortOrder: "desc",
                columns: [
                    {
                        visible: false,
                        field: 'id',
                        title: '教学物品编号'
                    },
                    {
                        field: 'name',
                        title: '名称'
                    },
                    {
                        field: 'unit',
                        title: '单位'
                    },
                    {
                        field: 'type',
                        title: '分类'
                    },
                    {
                        field: 'price',
                        title: '单价'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="delGoods(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                            return actions.join('');
                        }
                    }]
            };
            $.table.init(options);
        })

        // 加载选中教学物品
        function chooseGoodsIds(ids) {
            $("#ids").val(ids);
            $.table.search();
        }

        function delGoods(id) {
            table.set();
            $.modal.confirm("确定删除该条信息吗？", function() {
                var arr = $("#ids").val().split(',');
                arr = $.grep(arr, function(value) {
                    return value != id;
                });
                var ids = arr.join();
                $("#ids").val(ids);
                $.table.search();
            });
        }
    </script>
</body>
</html>